|
|
|
|
|
|
|
Listing 5.11. Adding code to the UserControl_InitProperties event. |
|
|
|
|
|
|
|
|
Private Sub UserControl_InitProperties()
'
With UserControl
.Width = 1200
.Height = 300
End With
'
Text1.Text = UserControl.Name
'
End Sub |
|
|
|
|
|
|
|
|
Along with the Resize and InitProperties events, there are two other very important events that you must populate with code. These are the ReadProperties and WriteProperties events of the UserControl. These two events are used to keep track of design-time property settings. When you set properties during design time, Visual Basic must have a way to store them so that the runtime version of Visual Basic knows what they are. |
|
|
|
|
|
|
|
|
Because we haven't defined any custom properties to remember, you won't be coding these two events until a bit later in the chapter. However, it is important that you remember to code the Read and Write property routines for each custom property you define for your control. If you fail to do this, you won't be able to access any of the design-time property values once your Visual Basic program starts running. |
|
|
|
|
|
|
|
|
Now that the maintenance steps have been addressed, it's time to add some functionality to the new control. |
|
|
|
|
|
|
|
|
Coding the KeyFilter Validations for the Custom Control |
|
|
|
|
|
|
|
|
The first validation routine to add to the custom control is the key press filter routines. In this example control, you add key press filters for upper case, digits, and numeric data. These routines work very much like the key press routines you coded in the first part of this chapter. You need to create a few properties, some default values, and a couple of events to handle key press validation. Listing 5.12 shows the declarations for the key press routines. Add this code to the general declaration section of your UserControl module. |
|
|
|
|
|